import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ComplexRegex {
    public static void main(String[] args) {
        String iso8601Regex="^(\\d{4})[-/](0[1-9]|1[0-2])[-/](0[1-9]|[12]\\d|3[01])[T ]([01]\\d|2[0-3])[:.-]([0-5]\\d)[:.-]([0-5]\\d)(?:\\.(\\d{1,3}))?(Z|[+-](?:0\\d|1[0-3]):[0-5]\\d)?$";
        String[] testDates = {
                "2023-10-05T14:30:45.123+08:00",
                "2023/12/31 23:59.59.999Z",
                "2023-02-30 25:00:00", // 非法日期
                "2023-13-01 12:00:00"  // 非法月份
        };

        Pattern pattern=Pattern.compile(iso8601Regex);
        for (String date : testDates) {
            Matcher matcher = pattern.matcher(date);
            if (matcher.matches()) {
                System.out.println("合法日期: " + date);
                System.out.println("年: " + matcher.group(1));
                System.out.println("月: " + matcher.group(2));
                System.out.println("日: " + matcher.group(3));
                System.out.println("时: " + matcher.group(4));
                System.out.println("分: " + matcher.group(5));
                System.out.println("秒: " + matcher.group(6));
                System.out.println("毫秒: " + (matcher.group(7) != null ? matcher.group(7) : "无"));
                System.out.println("时区: " + (matcher.group(8) != null ? matcher.group(8) : "无"));
                System.out.println("-------------------");
            } else {
                System.out.println("非法日期: " + date);
                System.out.println("-------------------");
            }
        }
    }
}
